package com.zj.web.controller;

import com.zj.service.GrabResult;
import com.zj.service.RedPacketService;
import com.zj.web.bean.RedPacketActivityDTO;
import com.zj.web.bean.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/auth/redpacket")
@RefreshScope //开启动态刷新
public class AuthRedPacketController {
    @Autowired
    private RedPacketService redPacketService;
    //查询所有的活动信息
    @GetMapping("/all")
    public ResponseEntity<ResponseResult> getAllRedPacketActivities(){
        List<RedPacketActivityDTO> redPacketActivityDTOS = redPacketService.getAllRedPacketActivities();
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(redPacketActivityDTOS).build());
    }
    //根据 活动id查询活动状态
    @GetMapping("/getRedPacketActivityStatusById/{activityId}")
    public ResponseEntity<ResponseResult> getRedPacketActivityStatusById(@PathVariable("activityId") Long activityId) {
        Integer status = redPacketService.getRedPacketActivityStatus(activityId);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(status).build());
    }
    //查询最新的活动信息
    @GetMapping("/getRedPacketActivity")
    public ResponseEntity<ResponseResult> getRedPacketActivity() {
        RedPacketActivityDTO redPacketActivityDTO = redPacketService.getRedPacketActivity();
        System.out.println("redPacketActivityDTO = " + redPacketActivityDTO);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(redPacketActivityDTO).build());
    }
}
